import i18n from "@/locales";

// 去空格
export let textTrim = (value) => {
    return value ? value.trim().length : false;
};



// 文本空格校验
export const textReg = (rule, value, callback) => {
    // console.log(rule.errTitle, value, callback)
    if (!textTrim(value)) {
        callback(new Error(i18n.global.t("createNftFormTest."+rule.errTitleKey)));
    }
    else {
        callback();
    }
};


// 属性校验
export const detailListReg = (rule, value, callback) => {
    let isReg = true;
    for (let i = 0; i < value.length; i++) {
        if (!isReg) {
            break;
        }
        let item = value[i];
        for (let key in item) {
            if (!textTrim(item[key])) {
                isReg = false;
            }
        }
    }
    if (isReg) {
        callback();
    } else {
        callback(new Error(i18n.global.t("createNftFormTest."+rule.errTitleKey)));
    }
};


// 数字校验
export const numberReg = (rule, value, callback) => {
    if(!value || !Number(value) || value<=0){
        callback(new Error(i18n.global.t("createNftFormTest."+rule.errTitleKey)));
    }else{
        callback();
    }
};


// 数组校验
export const arrReg = (rule, value, callback) =>{
    if(!value || value.length==0){
        callback(new Error(i18n.global.t("createNftFormTest."+rule.errTitleKey)));
    }else{
        callback();
    }
};